package com.xuecheng;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mysql.cj.QueryResult;
import com.xuecheng.base.model.PageParam;
import com.xuecheng.content.mapper.CourseBaseMapper;
import com.xuecheng.content.mapper.TeachplanMapper;
import com.xuecheng.content.model.dto.QueryCourseParamDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.impl.TeachplanServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.junit.jupiter.api.Test;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 冯佳鑫 又菜又爱学
 * @version 1.0
 * @DATE now()
 */

@SpringBootTest()

@MapperScan(basePackages = "com.xuecheng.content.mapper")
public class test {
    @Autowired
    private CourseBaseMapper courseBaseMapper;
    @Test
    void list(){
        System.out.println("ohmygod!");
        PageParam pageParam = new PageParam();
        pageParam.setPageNo(1);
        pageParam.setPageSize(5);
        Page<CourseBase> page = new Page<>(pageParam.getPageNo(),
                pageParam.getPageSize());
        QueryCourseParamDto queryCourseParamDto = new QueryCourseParamDto();
        queryCourseParamDto.setCourseName("java");
        queryCourseParamDto.setAuditStatus("202004");


        LambdaQueryWrapper<CourseBase> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(queryCourseParamDto.getCourseName()),
                CourseBase::getName,queryCourseParamDto.getCourseName());


        Page<CourseBase> courseBasePage = courseBaseMapper.selectPage(page, wrapper);
        System.out.println("总页数" + courseBasePage.getCurrent());
        System.out.println("查询到的记录" + courseBasePage.getRecords());
    }

    @Test
//    @Transactional
    void  test(){
        CourseBase courseBase1 = new CourseBase();
        CourseBase courseBase = courseBaseMapper.selectById(83);
        BeanUtils.copyProperties(courseBase,courseBase1);
        courseBase1.setName("fuckyou");
        int i = courseBaseMapper.updateById(courseBase1);
        System.out.println(i);

    }
    @Autowired
    TeachplanServiceImpl teachplanMapper;
    @Test
    void testteachplan(){

        List<TeachplanDto> teachplanDtos = teachplanMapper.selectTeachplan(117L);
        System.out.println(teachplanDtos.size());
    }
}
